package com.spring.demo.publicutil.thread;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author youjc
 */
public class T08_LockSupport8 {
    public static void main(String[] args) {
        Thread k = new Thread(()->{
           for(int i=0;i<10;i++){
               System.out.println("i = " + i);
               if(i == 5){
                   LockSupport.park();// 上锁
               }
               if(i == 8){
                   LockSupport.park();
               }
               try {
                   TimeUnit.SECONDS.sleep(1);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        k.start();
        LockSupport.unpark(k);// 释放锁
        LockSupport.unpark(k);
/*        try {
            TimeUnit.SECONDS.sleep(10);
            System.out.println("11");
            LockSupport.unpark(k);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/

    }
}
